﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using Yunwei.Domain.Models;

namespace Yunwei.Web.Areas.RRShop.Models
{
    public class DinnerTableViewModel
    {
        [Key]
        public int Id { get; set; }

        [Required]
        [Display(Name="名称")]
        [StringLength(50, MinimumLength = 1, ErrorMessage = "{2}到{1}个字符")]
        public string Name { get; set; }

        [Display(Name="简介")]
        [StringLength(100, MinimumLength = 1, ErrorMessage = "{2}到{1}个字符")]
        public string Description { get; set; }

        [Required]
        [Display(Name = "类型")]
        public short Type { get; set; }

        [Required]
        [Display(Name = "餐位费")]
        public decimal Price { get; set; }

        [Required]
        [Display(Name = "是否预定")]
        public short Status { get; set; }

        [Display(Name= "是否空位")]
        public bool IsReserved
        {
            get
            {
                return Status == 1;
            }
            set
            {
                if (value)
                    Status = 1;
                else
                    Status = 0;
            }
        }

        public String ReservedString
        {
            get
            {
                if (this.Status == 1)
                    return "fa-times red";
                else
                    return "fa-check green";
            }
        }

        public int Restaurant_Id { get; set; }

        private DinnerTable dinnerTable;
        public DinnerTable DinnerTable
        {
            get
            {
                if(dinnerTable==null)
                {
                    dinnerTable = new DinnerTable()
                    {
                        Description = this.Description,
                        Id = this.Id,
                        Name = this.Name,
                        Price = this.Price,
                        Restaurant_Id = this.Restaurant_Id,
                        Status = this.Status,
                        Type = this.Type
                    };
                }

                return dinnerTable;
            }
        }

        public static DinnerTableViewModel FromDinnerTable(DinnerTable dt)
        {
            DinnerTableViewModel dtvm = new DinnerTableViewModel()
            {
                Description = dt.Description,
                Id = dt.Id,
                Name = dt.Name,
                Price = dt.Price,
                Restaurant_Id = dt.Restaurant_Id,
                Status = dt.Status,
                Type = dt.Type
            };

            return dtvm;
        }
    }
}